
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      <link rel="icon" href="../../../../static/images/favicon.png">
      <meta name="generator" content="mkdocs-1.3.0, mkdocs-material-8.2.8">
    
    
      
        <title>容器化部署之 image mirror 加速方案 - WL4G DOCS</title>
      
    
    
      <link rel="stylesheet" href="../../../../assets/stylesheets/main.644de097.min.css">
      
        
        <link rel="stylesheet" href="../../../../assets/stylesheets/palette.e6a45f82.min.css">
        
      
    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../../../static/css/util.css">
    
    <script>__md_scope=new URL("../../../..",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent="">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#image-mirror" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
      <div data-md-component="outdated" hidden>
        <aside class="md-banner md-banner--warning">
          
        </aside>
      </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../../../.." title="WL4G DOCS" class="md-header__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            WL4G DOCS
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              容器化部署之 image mirror 加速方案
            
          </span>
        </div>
      </div>
    </div>
    
      <form class="md-header__option" data-md-component="palette">
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
          
            <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
            </label>
          
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
          
            <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3z"/></svg>
            </label>
          
        
      </form>
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="Select language">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="/en/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
                
                <li class="md-select__item">
                  <a href="/zh/" hreflang="zh" class="md-select__link">
                    简体中文
                  </a>
                </li>
                
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-tabs__inner md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../../.." class="md-tabs__link">
        Getting Started
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


  

<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../../../.." title="WL4G DOCS" class="md-nav__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    WL4G DOCS
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_1" data-md-state="indeterminate" type="checkbox" id="__nav_1" checked>
      
      
      
      
        <label class="md-nav__link" for="__nav_1">
          Getting Started
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Getting Started" data-md-level="1">
        <label class="md-nav__title" for="__nav_1">
          <span class="md-nav__icon md-icon"></span>
          Getting Started
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../.." class="md-nav__link">
        Introduction
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../../ABOUT_CN/" class="md-nav__link">
        About
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
          
          <div class="md-content" data-md-component="content">
            <article class="md-content__inner md-typeset">
              
                


<h1 id="image-mirror">容器化部署之 image mirror 加速方案<a class="headerlink" href="#image-mirror" title="Permanent link">&para;</a></h1>
<ul>
<li>相关文章：<a href="https://blogs.wl4g.com/archives/66">基于 nexus3+minio/s3 搭建 docker 镜像仓库</a></li>
</ul>
<h2 id="1">1. 常用公共镜像仓库<a class="headerlink" href="#1" title="Permanent link">&para;</a></h2>
<ul>
<li>DockerHub镜像仓库:</li>
<li>
<p>https://hub.docker.com/</p>
</li>
<li>
<p>阿里云镜像仓库：</p>
</li>
<li>
<p>https://cr.console.aliyun.com</p>
</li>
<li>
<p>google镜像仓库：</p>
</li>
<li>https://gcr.io/google-containers/</li>
<li>https://gcr.io/kubernetes-helm/</li>
<li>
<p>https://gcr.io/google-containers/pause</p>
</li>
<li>
<p>quay.io镜像仓库：</p>
</li>
<li>
<p>https://quay.io/repository/</p>
</li>
<li>
<p>elastic镜像仓库：</p>
</li>
<li>
<p>https://www.docker.elastic.co/</p>
</li>
<li>
<p>RedHat镜像仓库：</p>
</li>
<li>
<p>https://access.redhat.com/containers</p>
</li>
<li>
<p>华为云镜像仓库：</p>
</li>
<li>
<p>https://console.huaweicloud.com/swr</p>
</li>
<li>
<p>腾讯云镜像仓库：</p>
</li>
<li>https://console.cloud.tencent.com/tcr</li>
</ul>
<hr />
<h2 id="2">2. 墙内镜像加速<a class="headerlink" href="#2" title="Permanent link">&para;</a></h2>
<ul>
<li>阿里云镜像加速: https://cr.console.aliyun.com/</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1"></a><a href="#__codelineno-0-1"><span class="linenos" data-linenos="1 "></span></a>tee /etc/docker/daemon.json <span class="s">&lt;&lt;-&#39;EOF&#39;</span>
<a id="__codelineno-0-2" name="__codelineno-0-2"></a><a href="#__codelineno-0-2"><span class="linenos" data-linenos="2 "></span></a><span class="s">{</span>
<a id="__codelineno-0-3" name="__codelineno-0-3"></a><a href="#__codelineno-0-3"><span class="linenos" data-linenos="3 "></span></a><span class="s">  &quot;registry-mirrors&quot;: [&quot;https://hjbu3ivg.mirror.aliyuncs.com&quot;]</span>
<a id="__codelineno-0-4" name="__codelineno-0-4"></a><a href="#__codelineno-0-4"><span class="linenos" data-linenos="4 "></span></a><span class="s">}</span>
<a id="__codelineno-0-5" name="__codelineno-0-5"></a><a href="#__codelineno-0-5"><span class="linenos" data-linenos="5 "></span></a><span class="s">EOF</span>
</code></pre></div>
<ul>
<li>Dao Cloud 镜像加速: https://www.daocloud.io/mirror</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1"></a><a href="#__codelineno-1-1"><span class="linenos" data-linenos="1 "></span></a>curl -sSL https://get.daocloud.io/daotools/set_mirror.sh <span class="p">|</span> sh -s http://f1361db2.m.daocloud.io
</code></pre></div>
<ul>
<li>重启 Docker 服务：</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1"></a><a href="#__codelineno-2-1"><span class="linenos" data-linenos="1 "></span></a>systemctl daemon-reload <span class="o">&amp;&amp;</span> sudo systemctl restart docker
</code></pre></div>
<ul>
<li>检查配置生效</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1"></a><a href="#__codelineno-3-1"><span class="linenos" data-linenos="1 "></span></a>docker info <span class="p">|</span> grep Mirrors -A1
<a id="__codelineno-3-2" name="__codelineno-3-2"></a><a href="#__codelineno-3-2"><span class="linenos" data-linenos="2 "></span></a>Registry Mirrors:
<a id="__codelineno-3-3" name="__codelineno-3-3"></a><a href="#__codelineno-3-3"><span class="linenos" data-linenos="3 "></span></a> https://hjbu3ivg.mirror.aliyuncs.com/
</code></pre></div>
<ul>
<li>验证 pull 速度</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1"></a><a href="#__codelineno-4-1"><span class="linenos" data-linenos="1 "></span></a><span class="nb">time</span> docker pull centos
</code></pre></div>
<h2 id="3">3. 公私有镜像仓库同步<a class="headerlink" href="#3" title="Permanent link">&para;</a></h2>
<p>以下工具都不依赖docker环境，同步镜像时不落本地盘：</p>
<ul>
<li>（推荐）Open Container 的 <a href="https://github.com/containers/skopeo/blob/master/docs/skopeo-sync.1.md">skopeo-sync</a></li>
<li>阿里云 <a href="https://github.com/AliyunContainerService/image-syncer">image-syncer</a></li>
<li>腾讯云 <a href="https://github.com/tkestack/image-transfer">image-transfer</a></li>
</ul>
<p>可结合公网免费CICD工具githubAction、TravisCI、CircleCI、gitlabCI等，将gcr.io镜像定时同步到个人dockerhub账号下或国内阿里云镜像仓库中。</p>
<ul>
<li>image-syncer + github action 同步示例：https://github.com/willzhang/image-syncer</li>
<li>docker + TravisCI 同步示例：https://github.com/willzhang/pull-docker-images</li>
</ul>
<p>国内镜像源替换示例，针对部分国外镜像仓库无法访问问题，国内阿里云或dockerhub可能有转存镜像可用，拉取后需自行修改tag：</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1"></a><a href="#__codelineno-5-1"><span class="linenos" data-linenos="1 "></span></a>docker pull k8s.gcr.io/pause:3.2
<a id="__codelineno-5-2" name="__codelineno-5-2"></a><a href="#__codelineno-5-2"><span class="linenos" data-linenos="2 "></span></a><span class="c1"># 替换为</span>
<a id="__codelineno-5-3" name="__codelineno-5-3"></a><a href="#__codelineno-5-3"><span class="linenos" data-linenos="3 "></span></a>docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
</code></pre></div>
<hr />
<h2 id="4-skopeo">4. <font color=red>使用 skopeo 同步（推荐）</font><a class="headerlink" href="#4-skopeo" title="Permanent link">&para;</a></h2>
<blockquote>
<p>为啥推荐 skopeo，一方面因为属于 Open container 社区的，star 比如上腾讯阿里的也很多，二是上面2个工具亲测发现同步到 nexus docker hosted 仓库后发现没有目录结构（因为ContentType不是<code>application/vnd.docker.distribution.manifest.v2+json</code>，暂未未找到设置参数），只有 skopeo copy 或 sync 能指定格式为 docker ，同步后的都有目录结构（与 docker push 的一致）</p>
</blockquote>
<ul>
<li>
<p>官方文档：<a href="https://github.com/containers/skopeo/blob/main/docs/skopeo-sync.1.md">github.com/containers/skopeo/blob/main/docs/skopeo-sync.1.md</a></p>
</li>
<li>
<p>官方安装 <a href="https://github.com/containers/skopeo/blob/main/install.md">github.com/containers/skopeo/blob/main/install.md</a></p>
</li>
</ul>
<h3 id="41">4.1 使用官方原始包<a class="headerlink" href="#41" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1"></a><a href="#__codelineno-6-1"><span class="linenos" data-linenos=" 1 "></span></a><span class="c1"># Fedora:</span>
<a id="__codelineno-6-2" name="__codelineno-6-2"></a><a href="#__codelineno-6-2"><span class="linenos" data-linenos=" 2 "></span></a>sudo dnf install gpgme-devel libassuan-devel btrfs-progs-devel device-mapper-devel
<a id="__codelineno-6-3" name="__codelineno-6-3"></a><a href="#__codelineno-6-3"><span class="linenos" data-linenos=" 3 "></span></a>
<a id="__codelineno-6-4" name="__codelineno-6-4"></a><a href="#__codelineno-6-4"><span class="linenos" data-linenos=" 4 "></span></a><span class="c1"># RHEL/CentOS ≤ 7.x</span>
<a id="__codelineno-6-5" name="__codelineno-6-5"></a><a href="#__codelineno-6-5"><span class="linenos" data-linenos=" 5 "></span></a>sudo yum -y install skopeo
<a id="__codelineno-6-6" name="__codelineno-6-6"></a><a href="#__codelineno-6-6"><span class="linenos" data-linenos=" 6 "></span></a>
<a id="__codelineno-6-7" name="__codelineno-6-7"></a><a href="#__codelineno-6-7"><span class="linenos" data-linenos=" 7 "></span></a><span class="c1"># Ubuntu (`libbtrfs-dev` requires Ubuntu 18.10 and above):</span>
<a id="__codelineno-6-8" name="__codelineno-6-8"></a><a href="#__codelineno-6-8"><span class="linenos" data-linenos=" 8 "></span></a>sudo apt install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config
<a id="__codelineno-6-9" name="__codelineno-6-9"></a><a href="#__codelineno-6-9"><span class="linenos" data-linenos=" 9 "></span></a>
<a id="__codelineno-6-10" name="__codelineno-6-10"></a><a href="#__codelineno-6-10"><span class="linenos" data-linenos="10 "></span></a><span class="c1"># macOS:</span>
<a id="__codelineno-6-11" name="__codelineno-6-11"></a><a href="#__codelineno-6-11"><span class="linenos" data-linenos="11 "></span></a>brew install gpgme
<a id="__codelineno-6-12" name="__codelineno-6-12"></a><a href="#__codelineno-6-12"><span class="linenos" data-linenos="12 "></span></a>
<a id="__codelineno-6-13" name="__codelineno-6-13"></a><a href="#__codelineno-6-13"><span class="linenos" data-linenos="13 "></span></a><span class="c1"># Alpine</span>
<a id="__codelineno-6-14" name="__codelineno-6-14"></a><a href="#__codelineno-6-14"><span class="linenos" data-linenos="14 "></span></a>sudo apk add skopeo
</code></pre></div>
<h3 id="42-1-skopeo-docker">4.2 方案1：使用 <a href="https://github.com/wl4g-k8s/skopeo-docker">skopeo-docker</a> 增强镜像安装 <font color=red>(推荐) </font><a class="headerlink" href="#42-1-skopeo-docker" title="Permanent link">&para;</a></h3>
<ul>
<li>源码仓库: <a href="https://github.com/wl4g-k8s/skopeo-docker">github.com/wl4g-k8s/skopeo-docker</a></li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1"></a><a href="#__codelineno-7-1"><span class="linenos" data-linenos="1 "></span></a>docker run --rm docker.io/wl4g/skopeo:1.8.0 skopeo --help
<a id="__codelineno-7-2" name="__codelineno-7-2"></a><a href="#__codelineno-7-2"><span class="linenos" data-linenos="2 "></span></a><span class="c1"># 或</span>
<a id="__codelineno-7-3" name="__codelineno-7-3"></a><a href="#__codelineno-7-3"><span class="linenos" data-linenos="3 "></span></a>docker run --rm registry.cn-shenzhen.aliyuncs.com/wl4g-k8s/skopeo:1.8.0 skopeo --help
</code></pre></div>
<ul>
<li>4.2.1 简单使用</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-8-1" name="__codelineno-8-1"></a><a href="#__codelineno-8-1"><span class="linenos" data-linenos="1 "></span></a><span class="c1"># 查看指定仓库镜像的元数据</span>
<a id="__codelineno-8-2" name="__codelineno-8-2"></a><a href="#__codelineno-8-2"><span class="linenos" data-linenos="2 "></span></a>skopeo inspect docker://registry.fedoraproject.org/fedora:latest
<a id="__codelineno-8-3" name="__codelineno-8-3"></a><a href="#__codelineno-8-3"><span class="linenos" data-linenos="3 "></span></a>skopeo inspect docker://registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.22.2
<a id="__codelineno-8-4" name="__codelineno-8-4"></a><a href="#__codelineno-8-4"><span class="linenos" data-linenos="4 "></span></a>
<a id="__codelineno-8-5" name="__codelineno-8-5"></a><a href="#__codelineno-8-5"><span class="linenos" data-linenos="5 "></span></a><span class="c1"># copy指定仓库镜像到远程私有仓库</span>
<a id="__codelineno-8-6" name="__codelineno-8-6"></a><a href="#__codelineno-8-6"><span class="linenos" data-linenos="6 "></span></a>skopeo copy docker://registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.22.2 docker://mirror.registry.privaterepo.com/k8s/kube-scheduler
</code></pre></div>
<ul>
<li>4.2.2 将 aliyuncs 仓库中 kube-scheduer 镜像所有tags 全量同步到私有仓库</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1"></a><a href="#__codelineno-9-1"><span class="linenos" data-linenos="1 "></span></a>skopeo sync --src docker --dest docker registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler mirror.registry.privaterepo.com/k8s/kube-scheduler
</code></pre></div>
<ul>
<li>4.2.3 按需批量同步</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1"></a><a href="#__codelineno-10-1"><span class="linenos" data-linenos="1 "></span></a><span class="c1"># 指定需同步的 tags 规则</span>
<a id="__codelineno-10-2" name="__codelineno-10-2"></a><a href="#__codelineno-10-2"><span class="linenos" data-linenos="2 "></span></a>cat <span class="s">&lt;&lt;-&#39;EOF&#39; &gt; sync.yml</span>
<a id="__codelineno-10-3" name="__codelineno-10-3"></a><a href="#__codelineno-10-3"><span class="linenos" data-linenos="3 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com:</span>
<a id="__codelineno-10-4" name="__codelineno-10-4"></a><a href="#__codelineno-10-4"><span class="linenos" data-linenos="4 "></span></a><span class="s">    images-by-tag-regex:</span>
<a id="__codelineno-10-5" name="__codelineno-10-5"></a><a href="#__codelineno-10-5"><span class="linenos" data-linenos="5 "></span></a><span class="s">        google_containers/kube-scheduler: ^v1\.1[89]\.[1234]$|^v1\.2[123456789]\.[1234]$</span>
<a id="__codelineno-10-6" name="__codelineno-10-6"></a><a href="#__codelineno-10-6"><span class="linenos" data-linenos="6 "></span></a><span class="s">EOF</span>
<a id="__codelineno-10-7" name="__codelineno-10-7"></a><a href="#__codelineno-10-7"><span class="linenos" data-linenos="7 "></span></a>
<a id="__codelineno-10-8" name="__codelineno-10-8"></a><a href="#__codelineno-10-8"><span class="linenos" data-linenos="8 "></span></a><span class="c1"># 执行</span>
<a id="__codelineno-10-9" name="__codelineno-10-9"></a><a href="#__codelineno-10-9"><span class="linenos" data-linenos="9 "></span></a>skopeo sync --src yaml --dest docker sync.yml mirror.registry.privaterepo.com/public
</code></pre></div>
<ul>
<li>更多完整示例：<a href="https://github.com/wl4g-k8s/skopeo-docker/blob/main/example/sync.yml">github.com/wl4g-k8s/skopeo-docker/blob/main/example/sync.yml</a></li>
</ul>
<blockquote>
<p>如上将会从 aliyuncs 公共仓库 <code>registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler</code> 同步 <code>v1.18.1, v1.18.2 ... v1.21.1...v1.22.1,v1.22.2...</code> 到私有仓库 <code>mirror.registry.privaterepo.com/public/kube-scheduler</code></p>
<p>通常 skopeo 进程可能就在 privaterepo 私服上运行，可将 <code>mirror.registry.privaterepo.com</code> 解析到 <code>127.0.0.1</code> 以加速写入。</p>
</blockquote>
<p>同步到私有 nexus3 docker hosted 截图：<img alt="" src="https://blogs.wl4g.com:443/wp-content/uploads/2022/02/skopeo-sync1.png" /></p>
<hr />
<h2 id="5-2-image-syncer">5. 方案2：使用 image-syncer 同步<a class="headerlink" href="#5-2-image-syncer" title="Permanent link">&para;</a></h2>
<p>image-syncer 是阿里云开源的一个docker镜像同步工具，使用golang开发，可用来进行多对多镜像仓库同步，支持绝大多数主流docker镜像仓库服务。下面演示基本使用方法。</p>
<h3 id="51">5.1 二进制安装<a class="headerlink" href="#51" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1"></a><a href="#__codelineno-11-1"><span class="linenos" data-linenos="1 "></span></a>wget https://github.com/AliyunContainerService/image-syncer/releases/download/v1.3.0/image-syncer-v1.3.0-linux-amd64.tar.gz
<a id="__codelineno-11-2" name="__codelineno-11-2"></a><a href="#__codelineno-11-2"><span class="linenos" data-linenos="2 "></span></a>tar -zxvf image-syncer-*.tar.gz -C /usr/local/bin
</code></pre></div>
<h3 id="52">5.2 创建同步配置<a class="headerlink" href="#52" title="Permanent link">&para;</a></h3>
<p>如下示例为仓库级同步，更多同步参见官方文档：https://github.com/AliyunContainerService/image-syncer</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1"></a><a href="#__codelineno-12-1"><span class="linenos" data-linenos=" 1 "></span></a>cat &gt; config.yaml <span class="s">&lt;&lt;EOF</span>
<a id="__codelineno-12-2" name="__codelineno-12-2"></a><a href="#__codelineno-12-2"><span class="linenos" data-linenos=" 2 "></span></a><span class="s">auth:</span>
<a id="__codelineno-12-3" name="__codelineno-12-3"></a><a href="#__codelineno-12-3"><span class="linenos" data-linenos=" 3 "></span></a><span class="s">  #registry.hub.docker.com:</span>
<a id="__codelineno-12-4" name="__codelineno-12-4"></a><a href="#__codelineno-12-4"><span class="linenos" data-linenos=" 4 "></span></a><span class="s">  #  username: xxx</span>
<a id="__codelineno-12-5" name="__codelineno-12-5"></a><a href="#__codelineno-12-5"><span class="linenos" data-linenos=" 5 "></span></a><span class="s">  #  password: xxx</span>
<a id="__codelineno-12-6" name="__codelineno-12-6"></a><a href="#__codelineno-12-6"><span class="linenos" data-linenos=" 6 "></span></a><span class="s">  #k8s.gcr.io:</span>
<a id="__codelineno-12-7" name="__codelineno-12-7"></a><a href="#__codelineno-12-7"><span class="linenos" data-linenos=" 7 "></span></a><span class="s">  #  username: xxx</span>
<a id="__codelineno-12-8" name="__codelineno-12-8"></a><a href="#__codelineno-12-8"><span class="linenos" data-linenos=" 8 "></span></a><span class="s">  #  password: xxx</span>
<a id="__codelineno-12-9" name="__codelineno-12-9"></a><a href="#__codelineno-12-9"><span class="linenos" data-linenos=" 9 "></span></a><span class="s">  #registry.cn-shenzhen.aliyuncs.com:</span>
<a id="__codelineno-12-10" name="__codelineno-12-10"></a><a href="#__codelineno-12-10"><span class="linenos" data-linenos="10 "></span></a><span class="s">  #  username: xxx</span>
<a id="__codelineno-12-11" name="__codelineno-12-11"></a><a href="#__codelineno-12-11"><span class="linenos" data-linenos="11 "></span></a><span class="s">  #  password: xxx</span>
<a id="__codelineno-12-12" name="__codelineno-12-12"></a><a href="#__codelineno-12-12"><span class="linenos" data-linenos="12 "></span></a><span class="s">  mirror.registry.privaterepo.com:</span>
<a id="__codelineno-12-13" name="__codelineno-12-13"></a><a href="#__codelineno-12-13"><span class="linenos" data-linenos="13 "></span></a><span class="s">    username: xxx</span>
<a id="__codelineno-12-14" name="__codelineno-12-14"></a><a href="#__codelineno-12-14"><span class="linenos" data-linenos="14 "></span></a><span class="s">    password: xxx</span>
<a id="__codelineno-12-15" name="__codelineno-12-15"></a><a href="#__codelineno-12-15"><span class="linenos" data-linenos="15 "></span></a><span class="s">images:</span>
<a id="__codelineno-12-16" name="__codelineno-12-16"></a><a href="#__codelineno-12-16"><span class="linenos" data-linenos="16 "></span></a><span class="s">  k8s.gcr.io/metrics-server/metrics-server: mirror.registry.privaterepo.com/k8s/metrics-server</span>
<a id="__codelineno-12-17" name="__codelineno-12-17"></a><a href="#__codelineno-12-17"><span class="linenos" data-linenos="17 "></span></a><span class="s">  registry.cn-hangzhou.aliyuncs.com/google_containers/pause: mirror.registry.privaterepo.com/k8s/pause</span>
<a id="__codelineno-12-18" name="__codelineno-12-18"></a><a href="#__codelineno-12-18"><span class="linenos" data-linenos="18 "></span></a><span class="s">  registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver: mirror.registry.privaterepo.com/k8s/kube-apiserver</span>
<a id="__codelineno-12-19" name="__codelineno-12-19"></a><a href="#__codelineno-12-19"><span class="linenos" data-linenos="19 "></span></a><span class="s">  registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager: mirror.registry.privaterepo.com/k8s/kube-controller-manager</span>
<a id="__codelineno-12-20" name="__codelineno-12-20"></a><a href="#__codelineno-12-20"><span class="linenos" data-linenos="20 "></span></a><span class="s">  registry.cn-hangzhou.aliyuncs.com/google_containers/kubelet: mirror.registry.privaterepo.com/k8s/kubelet</span>
<a id="__codelineno-12-21" name="__codelineno-12-21"></a><a href="#__codelineno-12-21"><span class="linenos" data-linenos="21 "></span></a><span class="s">  registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler: mirror.registry.privaterepo.com/k8s/kube-scheduler</span>
<a id="__codelineno-12-22" name="__codelineno-12-22"></a><a href="#__codelineno-12-22"><span class="linenos" data-linenos="22 "></span></a><span class="s">EOF</span>
</code></pre></div>
<ul>
<li>执行同步，将从 <code>gcr.io</code> 同步至 <code>dockerhub</code> 及阿里云镜像仓库</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1"></a><a href="#__codelineno-13-1"><span class="linenos" data-linenos="1 "></span></a>image-syncer --proc<span class="o">=</span><span class="m">6</span> --config<span class="o">=</span>config.yaml --retries<span class="o">=</span><span class="m">3</span>
</code></pre></div>
<hr />
<h2 id="6-3-image-transfer">6. 方案3：使用 image-transfer 同步<a class="headerlink" href="#6-3-image-transfer" title="Permanent link">&para;</a></h2>
<div class="highlight"><pre><span></span><code><a id="__codelineno-14-1" name="__codelineno-14-1"></a><a href="#__codelineno-14-1"><span class="linenos" data-linenos="1 "></span></a>wget https://github.com/tkestack/image-transfer/releases/download/v1.2.3/image-transfer-linux-amd64.tar.gz
<a id="__codelineno-14-2" name="__codelineno-14-2"></a><a href="#__codelineno-14-2"><span class="linenos" data-linenos="2 "></span></a>tar -zxvf image-transfer-*.tar.gz -C /usr/local/bin
</code></pre></div>
<ul>
<li>创建同步配置，更多同步参见官方文档：https://github.com/tkestack/image-transfer</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-15-1" name="__codelineno-15-1"></a><a href="#__codelineno-15-1"><span class="linenos" data-linenos=" 1 "></span></a>cat <span class="s">&lt;&lt;-&#39;EOF&#39; &gt; registry-secret.yaml</span>
<a id="__codelineno-15-2" name="__codelineno-15-2"></a><a href="#__codelineno-15-2"><span class="linenos" data-linenos=" 2 "></span></a><span class="s">#registry.hub.docker.com:</span>
<a id="__codelineno-15-3" name="__codelineno-15-3"></a><a href="#__codelineno-15-3"><span class="linenos" data-linenos=" 3 "></span></a><span class="s">#  username: xxx</span>
<a id="__codelineno-15-4" name="__codelineno-15-4"></a><a href="#__codelineno-15-4"><span class="linenos" data-linenos=" 4 "></span></a><span class="s">#  password: xxx</span>
<a id="__codelineno-15-5" name="__codelineno-15-5"></a><a href="#__codelineno-15-5"><span class="linenos" data-linenos=" 5 "></span></a><span class="s">#k8s.gcr.io:</span>
<a id="__codelineno-15-6" name="__codelineno-15-6"></a><a href="#__codelineno-15-6"><span class="linenos" data-linenos=" 6 "></span></a><span class="s">#  username: xxx</span>
<a id="__codelineno-15-7" name="__codelineno-15-7"></a><a href="#__codelineno-15-7"><span class="linenos" data-linenos=" 7 "></span></a><span class="s">#  password: xxx</span>
<a id="__codelineno-15-8" name="__codelineno-15-8"></a><a href="#__codelineno-15-8"><span class="linenos" data-linenos=" 8 "></span></a><span class="s">#registry.cn-hangzhou.aliyuncs.com:</span>
<a id="__codelineno-15-9" name="__codelineno-15-9"></a><a href="#__codelineno-15-9"><span class="linenos" data-linenos=" 9 "></span></a><span class="s">#  username: xxx</span>
<a id="__codelineno-15-10" name="__codelineno-15-10"></a><a href="#__codelineno-15-10"><span class="linenos" data-linenos="10 "></span></a><span class="s">#  password: xxx</span>
<a id="__codelineno-15-11" name="__codelineno-15-11"></a><a href="#__codelineno-15-11"><span class="linenos" data-linenos="11 "></span></a><span class="s">mirror.registry.privaterepo.com:</span>
<a id="__codelineno-15-12" name="__codelineno-15-12"></a><a href="#__codelineno-15-12"><span class="linenos" data-linenos="12 "></span></a><span class="s">  username: xxx</span>
<a id="__codelineno-15-13" name="__codelineno-15-13"></a><a href="#__codelineno-15-13"><span class="linenos" data-linenos="13 "></span></a><span class="s">  password: xxx</span>
<a id="__codelineno-15-14" name="__codelineno-15-14"></a><a href="#__codelineno-15-14"><span class="linenos" data-linenos="14 "></span></a><span class="s">EOF</span>
<a id="__codelineno-15-15" name="__codelineno-15-15"></a><a href="#__codelineno-15-15"><span class="linenos" data-linenos="15 "></span></a>
<a id="__codelineno-15-16" name="__codelineno-15-16"></a><a href="#__codelineno-15-16"><span class="linenos" data-linenos="16 "></span></a>cat <span class="s">&lt;&lt;-&#39;EOF&#39; &gt; transfer-rule.yaml</span>
<a id="__codelineno-15-17" name="__codelineno-15-17"></a><a href="#__codelineno-15-17"><span class="linenos" data-linenos="17 "></span></a><span class="s">k8s.gcr.io/metrics-server/metrics-server: mirror.registry.privaterepo.com/k8s/metrics-server</span>
<a id="__codelineno-15-18" name="__codelineno-15-18"></a><a href="#__codelineno-15-18"><span class="linenos" data-linenos="18 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com/google_containers/pause: mirror.registry.privaterepo.com/k8s/pause</span>
<a id="__codelineno-15-19" name="__codelineno-15-19"></a><a href="#__codelineno-15-19"><span class="linenos" data-linenos="19 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver: mirror.registry.privaterepo.com/k8s/kube-apiserver</span>
<a id="__codelineno-15-20" name="__codelineno-15-20"></a><a href="#__codelineno-15-20"><span class="linenos" data-linenos="20 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager: mirror.registry.privaterepo.com/k8s/kube-controller-manager</span>
<a id="__codelineno-15-21" name="__codelineno-15-21"></a><a href="#__codelineno-15-21"><span class="linenos" data-linenos="21 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com/google_containers/kubelet: mirror.registry.privaterepo.com/k8s/kubelet</span>
<a id="__codelineno-15-22" name="__codelineno-15-22"></a><a href="#__codelineno-15-22"><span class="linenos" data-linenos="22 "></span></a><span class="s">registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler: mirror.registry.privaterepo.com/k8s/kube-scheduler</span>
<a id="__codelineno-15-23" name="__codelineno-15-23"></a><a href="#__codelineno-15-23"><span class="linenos" data-linenos="23 "></span></a><span class="s">EOF</span>
</code></pre></div>
<ul>
<li>执行同步，将从 <code>gcr.io</code> 同步至 <code>dockerhub</code> 及阿里云镜像仓库</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1"></a><a href="#__codelineno-16-1"><span class="linenos" data-linenos="1 "></span></a>image-transfer --securityFile<span class="o">=</span>./registry-secret.yaml --ruleFile<span class="o">=</span>./transfer-rule.yaml <span class="se">\</span>
<a id="__codelineno-16-2" name="__codelineno-16-2"></a><a href="#__codelineno-16-2"><span class="linenos" data-linenos="2 "></span></a>--ns<span class="o">=</span>default --registry<span class="o">=</span>ccr.ccs.tencentyun.com --routines<span class="o">=</span><span class="m">5</span> --retry<span class="o">=</span><span class="m">3</span>
</code></pre></div>
<h2 id="7">7. 配置容器引擎<a class="headerlink" href="#7" title="Permanent link">&para;</a></h2>
<h3 id="71-docker">7.1 docker<a class="headerlink" href="#71-docker" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-17-1" name="__codelineno-17-1"></a><a href="#__codelineno-17-1"><span class="linenos" data-linenos="1 "></span></a><span class="c1"># 向 deamon.json 中 registry-mirrors 字段追加新 mirror 地址</span>
<a id="__codelineno-17-2" name="__codelineno-17-2"></a><a href="#__codelineno-17-2"><span class="linenos" data-linenos="2 "></span></a>sudo jq --argjson new_mirror <span class="s1">&#39;[&quot;https://mirror.registry.privaterepo.com&quot;]&#39;</span> <span class="s1">&#39;.&quot;registry-mirrors&quot; += $new_mirror&#39;</span> /etc/docker/daemon.json
<a id="__codelineno-17-3" name="__codelineno-17-3"></a><a href="#__codelineno-17-3"><span class="linenos" data-linenos="3 "></span></a>
<a id="__codelineno-17-4" name="__codelineno-17-4"></a><a href="#__codelineno-17-4"><span class="linenos" data-linenos="4 "></span></a><span class="c1"># 重启</span>
<a id="__codelineno-17-5" name="__codelineno-17-5"></a><a href="#__codelineno-17-5"><span class="linenos" data-linenos="5 "></span></a>sudo systemctl restart docker
</code></pre></div>
<h3 id="72-containerd">7.2 containerd<a class="headerlink" href="#72-containerd" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-18-1" name="__codelineno-18-1"></a><a href="#__codelineno-18-1"><span class="linenos" data-linenos=" 1 "></span></a>sudo mkdir -p /etc/containerd/
<a id="__codelineno-18-2" name="__codelineno-18-2"></a><a href="#__codelineno-18-2"><span class="linenos" data-linenos=" 2 "></span></a>sudo containerd config default &gt; /etc/containerd/config.toml <span class="c1"># 追加修改以下内容</span>
<a id="__codelineno-18-3" name="__codelineno-18-3"></a><a href="#__codelineno-18-3"><span class="linenos" data-linenos=" 3 "></span></a>
<a id="__codelineno-18-4" name="__codelineno-18-4"></a><a href="#__codelineno-18-4"><span class="linenos" data-linenos=" 4 "></span></a>...
<a id="__codelineno-18-5" name="__codelineno-18-5"></a><a href="#__codelineno-18-5"><span class="linenos" data-linenos=" 5 "></span></a>    <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry<span class="o">]</span>
<a id="__codelineno-18-6" name="__codelineno-18-6"></a><a href="#__codelineno-18-6"><span class="linenos" data-linenos=" 6 "></span></a>      <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry.mirrors<span class="o">]</span>
<a id="__codelineno-18-7" name="__codelineno-18-7"></a><a href="#__codelineno-18-7"><span class="linenos" data-linenos=" 7 "></span></a>        <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry.mirrors.<span class="s2">&quot;docker.io&quot;</span><span class="o">]</span>
<a id="__codelineno-18-8" name="__codelineno-18-8"></a><a href="#__codelineno-18-8"><span class="linenos" data-linenos=" 8 "></span></a>          <span class="nv">endpoint</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;https://registry-1.docker.io&quot;</span><span class="o">]</span>
<a id="__codelineno-18-9" name="__codelineno-18-9"></a><a href="#__codelineno-18-9"><span class="linenos" data-linenos=" 9 "></span></a>        <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry.mirrors.<span class="s2">&quot;gcr.io&quot;</span><span class="o">]</span>
<a id="__codelineno-18-10" name="__codelineno-18-10"></a><a href="#__codelineno-18-10"><span class="linenos" data-linenos="10 "></span></a>          <span class="nv">endpoint</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;https://mirror.registry.privaterepo.com&quot;</span><span class="o">]</span>
<a id="__codelineno-18-11" name="__codelineno-18-11"></a><a href="#__codelineno-18-11"><span class="linenos" data-linenos="11 "></span></a>      <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry.configs<span class="o">]</span>
<a id="__codelineno-18-12" name="__codelineno-18-12"></a><a href="#__codelineno-18-12"><span class="linenos" data-linenos="12 "></span></a>        <span class="o">[</span>plugins.<span class="s2">&quot;io.containerd.grpc.v1.cri&quot;</span>.registry.configs.<span class="s2">&quot;mirror.registry.privaterepo.com&quot;</span>.auth<span class="o">]</span>
<a id="__codelineno-18-13" name="__codelineno-18-13"></a><a href="#__codelineno-18-13"><span class="linenos" data-linenos="13 "></span></a>          <span class="nv">auth</span> <span class="o">=</span> <span class="s2">&quot;d2w0ZzoxMjM0NTY=&quot;</span>
<a id="__codelineno-18-14" name="__codelineno-18-14"></a><a href="#__codelineno-18-14"><span class="linenos" data-linenos="14 "></span></a>          <span class="c1">## Priority use username-password.</span>
<a id="__codelineno-18-15" name="__codelineno-18-15"></a><a href="#__codelineno-18-15"><span class="linenos" data-linenos="15 "></span></a>          <span class="c1">## see:https://blogs.wl4g.com/archives/66#4.2</span>
<a id="__codelineno-18-16" name="__codelineno-18-16"></a><a href="#__codelineno-18-16"><span class="linenos" data-linenos="16 "></span></a>          <span class="c1">## see:https://github.com/containerd/cri/blob/master/docs/registry.md#configure-registry-endpoint</span>
<a id="__codelineno-18-17" name="__codelineno-18-17"></a><a href="#__codelineno-18-17"><span class="linenos" data-linenos="17 "></span></a>          <span class="nv">username</span> <span class="o">=</span> <span class="s2">&quot;wl4g&quot;</span>
<a id="__codelineno-18-18" name="__codelineno-18-18"></a><a href="#__codelineno-18-18"><span class="linenos" data-linenos="18 "></span></a>          <span class="nv">password</span> <span class="o">=</span> <span class="s2">&quot;123456&quot;</span>
<a id="__codelineno-18-19" name="__codelineno-18-19"></a><a href="#__codelineno-18-19"><span class="linenos" data-linenos="19 "></span></a>          <span class="c1">#identitytoken = &quot;&quot;</span>
<a id="__codelineno-18-20" name="__codelineno-18-20"></a><a href="#__codelineno-18-20"><span class="linenos" data-linenos="20 "></span></a>...
</code></pre></div>
<h3 id="73-k3s">7.3 k3s<a class="headerlink" href="#73-k3s" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-19-1" name="__codelineno-19-1"></a><a href="#__codelineno-19-1"><span class="linenos" data-linenos=" 1 "></span></a>sudo cat <span class="s">&lt;&lt;-EOF&gt;/etc/rancher/k3s/registries.yaml</span>
<a id="__codelineno-19-2" name="__codelineno-19-2"></a><a href="#__codelineno-19-2"><span class="linenos" data-linenos=" 2 "></span></a><span class="s"># see:https://rancher.com/docs/k3s/latest/en/installation/private-registry/#rewrites</span>
<a id="__codelineno-19-3" name="__codelineno-19-3"></a><a href="#__codelineno-19-3"><span class="linenos" data-linenos=" 3 "></span></a><span class="s">mirrors:</span>
<a id="__codelineno-19-4" name="__codelineno-19-4"></a><a href="#__codelineno-19-4"><span class="linenos" data-linenos=" 4 "></span></a><span class="s">  quay.io:</span>
<a id="__codelineno-19-5" name="__codelineno-19-5"></a><a href="#__codelineno-19-5"><span class="linenos" data-linenos=" 5 "></span></a><span class="s">    endpoint:</span>
<a id="__codelineno-19-6" name="__codelineno-19-6"></a><a href="#__codelineno-19-6"><span class="linenos" data-linenos=" 6 "></span></a><span class="s">      - &quot;https://mirror.registry.your-privaterepo./o&quot;</span>
<a id="__codelineno-19-7" name="__codelineno-19-7"></a><a href="#__codelineno-19-7"><span class="linenos" data-linenos=" 7 "></span></a><span class="s">    #rewrite:</span>
<a id="__codelineno-19-8" name="__codelineno-19-8"></a><a href="#__codelineno-19-8"><span class="linenos" data-linenos=" 8 "></span></a><span class="s">    #  &quot;^argoproj/(.*)&quot;: &quot;public/argoproj/$1&quot;</span>
<a id="__codelineno-19-9" name="__codelineno-19-9"></a><a href="#__codelineno-19-9"><span class="linenos" data-linenos=" 9 "></span></a><span class="s">  k8s.gcr.io:</span>
<a id="__codelineno-19-10" name="__codelineno-19-10"></a><a href="#__codelineno-19-10"><span class="linenos" data-linenos="10 "></span></a><span class="s">    endpoint:</span>
<a id="__codelineno-19-11" name="__codelineno-19-11"></a><a href="#__codelineno-19-11"><span class="linenos" data-linenos="11 "></span></a><span class="s">      - &quot;https://mirror.registry.your-privaterepo.io&quot;</span>
<a id="__codelineno-19-12" name="__codelineno-19-12"></a><a href="#__codelineno-19-12"><span class="linenos" data-linenos="12 "></span></a><span class="s">  gcr.io:</span>
<a id="__codelineno-19-13" name="__codelineno-19-13"></a><a href="#__codelineno-19-13"><span class="linenos" data-linenos="13 "></span></a><span class="s">    endpoint:</span>
<a id="__codelineno-19-14" name="__codelineno-19-14"></a><a href="#__codelineno-19-14"><span class="linenos" data-linenos="14 "></span></a><span class="s">      - &quot;https://mirror.registry.your-privaterepo.io&quot;</span>
<a id="__codelineno-19-15" name="__codelineno-19-15"></a><a href="#__codelineno-19-15"><span class="linenos" data-linenos="15 "></span></a><span class="s">configs:</span>
<a id="__codelineno-19-16" name="__codelineno-19-16"></a><a href="#__codelineno-19-16"><span class="linenos" data-linenos="16 "></span></a><span class="s">  &quot;mirror.registry.your-privaterepo.io&quot;:</span>
<a id="__codelineno-19-17" name="__codelineno-19-17"></a><a href="#__codelineno-19-17"><span class="linenos" data-linenos="17 "></span></a><span class="s">    auth:</span>
<a id="__codelineno-19-18" name="__codelineno-19-18"></a><a href="#__codelineno-19-18"><span class="linenos" data-linenos="18 "></span></a><span class="s">      username: &#39;&lt;your username&gt;&#39;</span>
<a id="__codelineno-19-19" name="__codelineno-19-19"></a><a href="#__codelineno-19-19"><span class="linenos" data-linenos="19 "></span></a><span class="s">      password: &#39;&lt;your password&gt;&#39;</span>
<a id="__codelineno-19-20" name="__codelineno-19-20"></a><a href="#__codelineno-19-20"><span class="linenos" data-linenos="20 "></span></a><span class="s">EOF</span>
<a id="__codelineno-19-21" name="__codelineno-19-21"></a><a href="#__codelineno-19-21"><span class="linenos" data-linenos="21 "></span></a>
<a id="__codelineno-19-22" name="__codelineno-19-22"></a><a href="#__codelineno-19-22"><span class="linenos" data-linenos="22 "></span></a><span class="c1"># 重启</span>
<a id="__codelineno-19-23" name="__codelineno-19-23"></a><a href="#__codelineno-19-23"><span class="linenos" data-linenos="23 "></span></a>sudo systemctl restart k3s
<a id="__codelineno-19-24" name="__codelineno-19-24"></a><a href="#__codelineno-19-24"><span class="linenos" data-linenos="24 "></span></a>
<a id="__codelineno-19-25" name="__codelineno-19-25"></a><a href="#__codelineno-19-25"><span class="linenos" data-linenos="25 "></span></a><span class="c1"># 测试从 k8s.gcr.io 拉镜像，拉取成功后可以在 nexus/harbor 控制台看到缓存的这个镜像</span>
<a id="__codelineno-19-26" name="__codelineno-19-26"></a><a href="#__codelineno-19-26"><span class="linenos" data-linenos="26 "></span></a>sudo k3s crictl pull k8s.gcr.io/kube-state-metrics/kube-state-metrics:v2.3.0
</code></pre></div>
<ul>
<li>
<p>相关更多集成配置参见：<a href="https://blogs.wl4g.com/archives/66">基于 nexus3+minio/s3 搭建 docker 镜像仓库</a></p>
</li>
<li>
<p>更多关于 <code>jq</code> 高级用法，参见官方：https://stedolan.github.io/jq/  或 https://qa.1r1g.cn/unix/ask/32268981/</p>
</li>
</ul>
<h2 id="8">8. 参考资料<a class="headerlink" href="#8" title="Permanent link">&para;</a></h2>
<ul>
<li>https://docs.docker.com/config/daemon/systemd/#httphttps-proxy</li>
<li>https://blog.csdn.net/nklinsirui/article/details/80581286</li>
<li>https://www.cnblogs.com/xuxinkun/p/11025020.html</li>
</ul>

              
            </article>
          </div>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    <script id="__config" type="application/json">{"base": "../../../..", "features": ["search.suggest", "search.highlight", "navigation.tabs", "navigation.expand", "toc.follow", "toc.integrate"], "search": "../../../../assets/javascripts/workers/search.5e67fbfe.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version.title": "Select version"}, "version": {"default": "latest", "provider": "mike"}}</script>
    
    
      <script src="../../../../assets/javascripts/bundle.c44cc438.min.js"></script>
      
        <script src="../../../../static/js/util.js"></script>
      
    
  </body>
</html>